const express = require("express")
const router = express.Router()
const {Tag} = require("../models")
const {Op, literal} = require("sequelize")

const {success} = require("../utils/response")

/**
 * 标签列表
 */
router.get("/", async (req, res, next) => {
    try {
        const categories = await Tag.findAll({
            order: [['id', 'DESC']],
        })
        success(res, "查询标签列表成功", categories)
    } catch(err) {
        next(err)
    }
})

/**
 *
 */
router.get("/rand", async (req, res, next) => {
    try {
        const categories = await Tag.findAll({
            order: literal('RAND()'),
            limit: 5
        })
        success(res, "查询随机标签列表成功", categories)
    } catch(err) {
        next(err)
    }
})

module.exports = router